#include "Reflector.h"

using namespace std;
using namespace OpenRA::Game::Trait;
using namespace OpenRA::Game::Tools;

/***************************************************
 * 此段代码确保单例
 */
Reflector *Reflector::reflector_p = nullptr;


/***************************************************
 * 此段代码实现反射器
 */
bool Reflector::Register(const string& className, const function<TraitInfo*()>& createFunc)
{
	if(nullptr == createFunc)
		return false;
	return create_functions.insert(make_pair(className, createFunc)).second;
}

TraitInfo* Reflector::Create(const string& className)
{
	auto iter = create_functions.find(className);
	if(create_functions.end() == iter)
		return nullptr;
	else
		return iter->second();
}
